<template>
  <div class="container" id="app">
    <div class="middle_box">
      <el-form ref="fm" :model="fm" class="login_form">
        <el-form-item prop="phone" :rules="{required: true, message: '请输入手机号'}">
          <el-input type="text" v-model="fm.phone" placeholder="手机号" icon="fa-user" autofocus></el-input>
        </el-form-item>
        <el-form-item prop="password" :rules="{required: true, message: '请输入密码'}">
          <el-input type="password" v-model="fm.password" placeholder="密码" icon="fa-lock" autofocus></el-input>
        </el-form-item>
        <el-button type="primary" @click="login" class="mybtn">登 录</el-button>
        <el-button @click="register" type="text">没有账号？去注册</el-button>
      </el-form>
    </div>
  </div>
</template>

<script>
import API from "../../utils/Api";
export default {
  data() {
    return {
      fm: {}
    };
  },
  methods: {
    login() {
      let self = this;
      this.$refs["fm"].validate(d => {
        if (d) {
          API.auth.login(self.fm, res => {
            if (res.code === 200) {
              window.sessionStorage.TOKEN = res.data;
              self.$router.push("/");
            } else {
              self.$message({
                type: "error",
                message: "账号或密码错误"
              });
            }
          });
        } else {
          self.$message({
            type: "warning",
            message: "请输入手机号和密码"
          });
        }
      });
    },
    register() {
      this.$router.push("/register");
    }
  }
};
</script>
<style>
.middle_box {
  width: 500px;
  padding: 60px;
  background-color: #ffffff;
  border-radius: 3px;
  box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.06);
  box-sizing: border-box;
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.login_form {
  width: 100%;
}

.mybtn {
  width: 100%;
}
</style>
<style scoped>
#app {
  background-image: url("../../assets/imgs/bg.png");
  display: flex;
  display: -webkit-flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  position: fixed;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
</style>